<?php
declare (strict_types = 1);

namespace addons\V2\admin\controller;

use think\facade\View;

class ProductCate extends \app\admin\controller\Base
{

    protected string $pk = 'id';

    protected string $model = '\addons\V2\admin\model\ProductCate';

    public function index()
    {

        View::assign('list', $this->model::getAll());
        return View::fetch($this->app->getRootPath() . 'addons/V2/admin/view/product_cate/index.html');
    }

    public function edit($id = '', $pid = '', $tpl = '')
    {
        $p_title = '';
        if ($pid) {
            $p_title = $this->model::where('id', $pid)->value('title');
        }

        View::assign('p_title', $p_title);
        View::assign('form', ['title' => '图标', 'field' => 'icon', 'value' => 1]);
        return parent::edit($id, $this->app->getRootPath() . 'addons/V2/admin/view/product_cate/edit.html');
    }


    public function getCate()
    {
        $id = $this->request->param('id', 0);
        return json($this->model::getCate($id));
    }
}
